#ifndef PROJECTEVENTHANDLER_H
#define PROJECTEVENTHANDLER_H

#ifdef _WIN32
#include <windows.h>
#endif

#include "../../SDK/include/CinePlugin.h"
#include "project_p.h"

class IProjectPlugin;
class ProjectEventBus;
class ProjectEventHandler : public IEventHandler
{
    public:
        static ProjectEventHandler* self();
        virtual ~ProjectEventHandler();
        virtual bool HandleEvent( Events::Event* event );

        /// load sub plugins
        bool LoadProjectPlugin( const std::string& plugin_file );
        void ReleaseProjectPlugin( const std::string& plugin_file );

        /// file management
        bool addFile( const std::string& file );
        bool renameFile( const std::string& orig, const std::string& replace );
        bool removeFile( const std::string& file );
        bool removeFileOnDisk( const std::string& file );
        bool addFolder( const std::string& folder, bool recursive = true );
        bool renameFolder( const std::string& orig, const std::string& replace );
        bool removeFolder( const std::string& folder );
        bool removeFolderOnDisk( const std::string& folder );
        
    private:
        static ProjectEventHandler* m_self;
        ProjectEventHandler();

        // for binary compability
        ProjectPrivate* d;
        
        /// singleton member
        ProjectEventBus* m_bus;
        
        /// store plugin instance pointer and its library
#ifdef _WIN32
        typedef struct { IProjectPlugin* p; HINSTANCE lib; } plugin_t;
#else
        typedef struct { IProjectPlugin* p; void* lib; } plugin_t;
#endif
        std::vector<plugin_t> loaded_plugins;


    private:
        friend class ProjectUI;
        unsigned int cmd_import, cmd_export;
        unsigned int cmd_build, cmd_clean, cmd_rebuild;
        unsigned int cmd_configure;

//         ProjectImportEvent* dataevent;
};

#endif // PROJECTEVENTHANDLER_H
